﻿'******************************************************
'******************************************************
'Application Title: Google Widget Editor
'version: 1.0
'Date: 01-02-2008
'Requirements: win2k or later
'Author: Andrew Pye
'Author Email: StretchMasterP@googlemail.com
'License: Released under GNU GENERAL PUBLIC LICENSE v3
'ToDo:
'Changes:Imports System.Text
'******************************************************
'******************************************************

Imports System.Text
Imports System.ComponentModel

Public Class ModulePrefs
    Implements IObjectName

#Region "Enum"
    Public Enum enumGoogleCategorys
        News
        Tools
        Communication
        Fun_Games
        Finance
        Sports
        Lifestyle
        Technology
        Politics
    End Enum
#End Region
    '<ModulePrefs title="__MSG_title__"
    'author="James L."
    'author_email="jameslee+datetime@google.com"
    'author_affiliation="Google Inc."
    'author_location="Mountain View, CA"
    'screenshot="/ig/modules/datetime_v2_content/__MSG_locale__.png"
    'thumbnail="/ig/modules/datetime_v2_content/__MSG_locale__-thm.png"
    'category="tools"
    'description="__MSG_description__"
    'render_inline="optional" height="140" scaling="false">
    '</ModulePrefs>

#Region "Fields"
    Private _title As String = String.Empty
    Private _author As String = String.Empty
    Private _author_email As String = String.Empty
    Private _author_affiliation As String = String.Empty
    Private _author_location As String = String.Empty
    Private _screenshot As String = String.Empty
    Private _thumbnail As String = String.Empty
    Private _category As enumGoogleCategorys = enumGoogleCategorys.Tools
    Private _category2 As enumGoogleCategorys = enumGoogleCategorys.Tools
    Private _description As String = String.Empty
    Private _render_inline As String = String.Empty
    Private _height As String = String.Empty
    Private _width As String = String.Empty
    Private _scaling As Boolean = False
    Private _author_link As String = String.Empty
    Private _directory_title As String = String.Empty
    Private _title_url As String = String.Empty
    Private _author_photo As String = String.Empty
    Private _scrolling As Boolean = False
    Private _UserPrefs As UserPrefs = Nothing
    Private _oAuth As oAuth = Nothing
    Private _Parent As Widget = Nothing
    Private _IsDirty As Boolean = False
#End Region
#Region "Constructor"
    Public Sub New()
        _UserPrefs = New UserPrefs
        _oAuth = New oAuth
        _UserPrefs.SetParent(Me)
    End Sub
#End Region
#Region "Methods"
    Public Sub SetDirty()
        If Me.Parent IsNot Nothing Then Me.Parent.SetDirty()
    End Sub
    ''' <summary>
    ''' Add User Prefs
    ''' </summary>
    ''' <param name="Name"></param>
    ''' <param name="Display_name"></param>
    ''' <param name="Default_value"></param>
    ''' <param name="Datatype"></param>
    ''' <returns></returns>
    ''' <remarks></remarks>
    Public Function AddUserPref(ByVal Name As String, ByVal Display_name As String, ByVal Default_value As String, ByVal Datatype As UserPref.EnumDataType) As UserPref
        If Me._UserPrefs Is Nothing Then Me._UserPrefs = New UserPrefs()
        Return Me.UserPrefs.Add(Name, Display_name, Default_value, Datatype)
    End Function
    ''' <summary>
    ''' Build the Ouput for Module Prefs
    ''' </summary>
    ''' <returns></returns>
    ''' <remarks></remarks>
    Public Function BuildXml(Optional ByVal Require As String = "") As String
        Dim sb As StringBuilder = New StringBuilder
        sb.AppendLine("<ModulePrefs title='" & Me.Title & "' ")
        sb.AppendLine(" directory_title = '" & Me.Directory_title & "' ")
        sb.AppendLine(" Author = '" & Me.Author & "' ")
        sb.AppendLine(" Author_email = '" & Me.Author_email & "' ")
        sb.AppendLine(" author_link = '" & Me.Author_link & "' ")
        sb.AppendLine(" author_photo = '" & Me.Author_photo & "' ")
        sb.AppendLine(" category = '" & Me.Category.ToString & "' ")
        sb.AppendLine(" category2 = '" & Me.Category2.ToString & "' ")
        sb.AppendLine(" Render_inline = '" & Me.Render_inline & "' ")
        sb.AppendLine(" title_url = '" & Me.Title_url & "' ")
        sb.AppendLine(" Thumbnail = '" & Me.Thumbnail & "' ")
        sb.AppendLine(" Width = '" & Me.Width & "' ")
        sb.AppendLine(" Height = '" & Me.Height & "' ")
        sb.AppendLine(" Description = '" & Me.Description & "' ")
        sb.AppendLine(" scrolling = '" & Me.Scrolling & "'> ")
        If Not String.IsNullOrEmpty(Require) Then sb.AppendLine(Require)
        sb.AppendLine(Me.oAuth.BuildXml)
        sb.AppendLine("</ModulePrefs>")
        For Each Tobj As UserPref In Me.UserPrefs
            Dim strbuf As String = Tobj.BuildXml.ToString.Trim
            If Not String.IsNullOrEmpty(strbuf) Then
                sb.AppendLine(Tobj.BuildXml())
            End If
        Next


        Return sb.ToString
    End Function

#End Region
#Region "Properties"
    <Browsable(False)> _
    Public Property IsDirty() As Boolean
        Get
            Return _IsDirty
        End Get
        Set(ByVal value As Boolean)
            _IsDirty = value
            Me.SetDirty()
        End Set
    End Property
    Protected ReadOnly Property Parent() As Object Implements IObjectName.Parent
        Get
            Return _Parent
        End Get
    End Property
    Public Sub SetParent(ByVal ParentObject As Object) Implements IObjectName.SetParent
        _Parent = ParentObject
    End Sub
    <CategoryAttribute("Google"), Description("Category of the Widget")> _
    Public Property Category2() As enumGoogleCategorys
        Get
            Return _category2
        End Get
        Set(ByVal value As enumGoogleCategorys)
            _category2 = value
            Me.SetDirty()

        End Set
    End Property
    <CategoryAttribute("Author"), Description("Author of the Widget")> _
    Public Property Author() As String
        Get
            Return _author
        End Get
        Set(ByVal value As String)
            _author = value
            Me.SetDirty()
        End Set
    End Property
    <CategoryAttribute("Author"), Description("Author Affiliation")> _
    Public Property Author_affiliation() As String
        Get
            Return _author_affiliation
        End Get
        Set(ByVal value As String)
            _author_affiliation = value
            Me.SetDirty()
        End Set
    End Property
    <CategoryAttribute("Author"), Description("Email Address of the Author")> _
    Public Property Author_email() As String
        Get
            Return _author_email
        End Get
        Set(ByVal value As String)
            _author_email = value
            Me.SetDirty()
        End Set
    End Property
    <CategoryAttribute("Author"), Description("Location of the Author")> _
    Public Property Author_location() As String
        Get
            Return _author_location
        End Get
        Set(ByVal value As String)
            _author_location = value
            Me.SetDirty()
        End Set
    End Property
    <CategoryAttribute("Author"), Description("Link to Author Website")> _
    Public Property Author_link() As String
        Get
            Return _author_link
        End Get
        Set(ByVal value As String)
            _author_link = value
            Me.SetDirty()
        End Set
    End Property
    <CategoryAttribute("Author"), Description("Photo of the Author")> _
    Public Property Author_photo() As String
        Get
            Return _author_photo
        End Get
        Set(ByVal value As String)
            _author_photo = value
            Me.SetDirty()
        End Set
    End Property
    <CategoryAttribute("Google"), Description("Widget Title in Directory")> _
    Public Property Directory_title() As String
        Get
            Return _directory_title
        End Get
        Set(ByVal value As String)
            _directory_title = value
            Me.SetDirty()
        End Set
    End Property
    <CategoryAttribute("Widget Settings"), Description("Show Scroll Bars")> _
    Public Property Scrolling() As Boolean
        Get
            Return _scrolling
        End Get
        Set(ByVal value As Boolean)
            _scrolling = value
            Me.SetDirty()
        End Set
    End Property
    <CategoryAttribute("Widget Info"), Description("????")> _
    Public Property Title_url() As String
        Get
            Return _title_url
        End Get
        Set(ByVal value As String)
            _title_url = value
            Me.SetDirty()
        End Set
    End Property
    <CategoryAttribute("Widget Settings"), _
    BrowsableAttribute(False), Description("Collection of User Prefs")> _
    Public Property UserPrefs() As UserPrefs
        Get
            Return _UserPrefs
        End Get
        Set(ByVal value As UserPrefs)
            _UserPrefs = value
            Me.SetDirty()
        End Set
    End Property
    <CategoryAttribute("Widget Settings"), _
    BrowsableAttribute(False), Description("oAuth Settings")> _
    Public Property oAuth() As oAuth
        Get
            Return _oAuth
        End Get
        Set(ByVal value As oAuth)
            _oAuth = value
            Me.SetDirty()
        End Set
    End Property
    <CategoryAttribute("Google"), Description("Category of the Widget")> _
    Public Property Category() As enumGoogleCategorys
        Get
            Return _category
        End Get
        Set(ByVal value As enumGoogleCategorys)
            _category = value
            Me.SetDirty()
        End Set
    End Property
    <CategoryAttribute("Widget Info"), Description("Widget Description")> _
    Public Property Description() As String
        Get
            Return _description
        End Get
        Set(ByVal value As String)
            _description = value
            Me.SetDirty()
        End Set
    End Property
    <CategoryAttribute("Widget Settings"), Description("Height of the Widget")> _
    Public Property Height() As String
        Get
            Return _height
        End Get
        Set(ByVal value As String)
            _height = value
            Me.SetDirty()
        End Set
    End Property
    <CategoryAttribute("Widget Settings"), Description("?????")> _
    Public Property Render_inline() As String
        Get
            Return _render_inline
        End Get
        Set(ByVal value As String)
            _render_inline = value
            Me.SetDirty()
        End Set
    End Property
    <CategoryAttribute("Widget Settings"), Description("?????")> _
    Public Property Scaling() As Boolean
        Get
            Return _scaling
        End Get
        Set(ByVal value As Boolean)
            _scaling = value
            Me.SetDirty()
        End Set
    End Property
    <CategoryAttribute("Google"), Description("Screenshot Url of the Widget")> _
    Public Property Screenshot() As String
        Get
            Return _screenshot
        End Get
        Set(ByVal value As String)
            _screenshot = value
            Me.SetDirty()
        End Set
    End Property
    <CategoryAttribute("Google"), Description("Thumbnail Url of the Widget")> _
    Public Property Thumbnail() As String
        Get
            Return _thumbnail
        End Get
        Set(ByVal value As String)
            _thumbnail = value
            Me.SetDirty()
        End Set
    End Property
    <CategoryAttribute("Widget Info"), Description("Title of the Widget")> _
    Public Property Title() As String
        Get
            Return _title
        End Get
        Set(ByVal value As String)
            _title = value
            Me.SetDirty()
        End Set
    End Property
    <CategoryAttribute("Widget Settings"), Description("Width of the Widget")> _
    Public Property Width() As String
        Get
            Return _width
        End Get
        Set(ByVal value As String)
            _width = value
            Me.SetDirty()
        End Set
    End Property
    <BrowsableAttribute(False)> _
    Public ReadOnly Property ObjectName() As String Implements IObjectName.ObjectName
        Get
            Return "ModulePrefs"
        End Get
    End Property
#End Region

    
    Protected Overrides Sub Finalize()
        MyBase.Finalize()
        _oAuth = Nothing
        _UserPrefs = New UserPrefs
    End Sub
End Class
